'''
Created on Feb 6, 2011

@author: inyaky
'''
from google.appengine.ext.webapp import template
from model.uUserAdapter import UserAdapter
from view.renderers.uRenderable import Renderable
from google.appengine.ext import db
import os
import uConst

class MainPageRen(Renderable):
    
    def __init__(self, aEnviroment):
        self._enviroment = aEnviroment
        
    def render(self):
        
        user = UserAdapter(self._enviroment)
        if user.isLogged():
            
            category_list = []
            for aCategory in user.getCategoryList():
                category_list = category_list + aCategory.toRenderable()
            
                
            task_list = []
            for aTask in user.getTaskList():
                task_list = task_list + aTask.toRenderable()
               
            
            values = {
                      'category_list':category_list,
                      'task_list':task_list,
                      'user':user.toRenderable()
            }
            
            path = os.path.join(self._enviroment.path, uConst.INDEX)
            self._enviroment.response.out.write(template.render(path, values))
        
        else:
            user.LogIn()
        
        
    
